// index.js
import http from "../../request/index"
// 获取应用实例
const app = getApp()

Page({
  data: {
    indicatorDots: true,
    vertical: true,
    autoplay: true,
    interval: 2000,
    duration: 500,
    banner: [],
    NAV: [],
    foot: [],
    statusBarHeight: 0, //状态栏高度
    searchWidth: 100, //搜索框的宽度
    searchHeight: 100, //搜索框的高度
    searchMarginTop: 0, //搜索框上边距
    navHeight: 0
  },
  // 事件处理函数
  inp() {
    wx.navigateTo({
      url: "../sou/sou"
    })
  },
  gitinp() {
    const res = wx.getMenuButtonBoundingClientRect()
    console.log(res);
    const {
      top,
      width,
      height,
      right
    } = res //获取胶囊的信息
    wx.getSystemInfo({
      success: res => {
        const {
          statusBarHeight
        } = res
        const margin = top - statusBarHeight
        console.log((height + statusBarHeight + (margin * 2)));
        this.setData({
          statusBarHeight: statusBarHeight,
          navHeight: (height + statusBarHeight + (margin * 2)),
          searchMarginTop: statusBarHeight + margin, // 状态栏 + 胶囊按钮边距
          searchHeight: height, // 与胶囊按钮同高
          searchWidth: right - width - 30 // 胶囊按钮右边坐标 - 胶囊按钮宽度 = 按钮左边可使用宽度，再减去30两边间距
        })

      }
    })
  },
  onLoad() {
    this.gitinp()

    //轮播图
    http("public/v1/home/swiperdata", {
      mmethod: "get",
      data: {}
    }).then(res => {
      let {
        data
      } = res
      if (data.meta.status == 200) {
        this.setData({
          banner: data.message
        })
      }
    })
    //轮播图
    http("public/v1/home/catitems", {
      mmethod: "get",
      data: {}
    }).then(res => {
      if (res.data.meta.status == 200) {
        let {
          data
        } = res
        this.setData({
          NAV: data.message
        })
      }
    })
    http("public/v1/home/floordata", {
      mmethod: "get",
      data: {}
    }).then(res => {
      if (res.data.meta.status == 200) {
        let {
          data
        } = res
        this.setData({
          foot: data.message
        })
      }
    })
  },
  img(e) {
    let str = e.currentTarget.dataset.name.split('=')[1]
    wx.navigateTo({
      url: '../list/list?query=' + str,
    })
  },
  getUserProfile(e) {

  },
  getUserInfo(e) {

  }
})